<template>
  <div>
    <div style="margin-bottom: 10px">
      <img class="img" src="../../../assets/images/PetCare/u0.png" alt="" />
    </div>
    <div class="content">
      <div>
        <!-- <el-row>
          <el-col :span="2">
            <el-dropdown>
          <span class="el-dropdown-link">
              全国
            <el-icon class="el-icon--right">
              <arrow-down/>
            </el-icon>
          </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>Action 1</el-dropdown-item>
                  <el-dropdown-item>Action 2</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-col>
          <el-col :span="2">
            <el-dropdown>
          <span class="el-dropdown-link">
            性别
            <el-icon class="el-icon--right">
              <arrow-down/>
            </el-icon>
          </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>Action 1</el-dropdown-item>
                  <el-dropdown-item>Action 2</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-col>
          <el-col :span="2">
            <el-dropdown>
          <span class="el-dropdown-link">
            种类
            <el-icon class="el-icon--right">
              <arrow-down/>
            </el-icon>
          </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>Action 1</el-dropdown-item>
                  <el-dropdown-item>Action 2</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-col>
          <el-col :span="2">
            <el-dropdown>
          <span class="el-dropdown-link">
            最新发布
            <el-icon class="el-icon--right">
              <arrow-down/>
            </el-icon>
          </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>Action 1</el-dropdown-item>
                  <el-dropdown-item>Action 2</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-col>
        </el-row> -->
      </div>
      <div class="list">
        <div
          class="item"
          v-for="item in list"
          :key="item.id"
          @click="pushDetail(item)"
        >
          <div style="width: 100%; height: 150px">
            <img style="width: 100%; height: 150px;object-fit: contain;" :src="item.cover" alt=""  />
          </div>
          <div style="font-size: 24px" class="name">
            <div style="color: #333333">{{ item.petName }}</div>
            <div style="color: #aaaaaa; font-size: 20px">
              {{ moment(dateString).format('YYYY-MM-DD') }}
            </div>
          </div>
          <div class="info">
            <div class="info-1">{{ item.variety }}</div>
            <div class="info-2">{{ item.sex }}</div>
            <div class="info-3">{{ item.area }}</div>
          </div>
          <div class="text">
            {{ item.comment }}
          </div>
        </div>
      </div>
      <div class="pagination">
        <el-pagination
          layout="prev, pager, next"
          :total="total"
          :page-size="pageSize"
          v-model:current-page="pageNum"
          @change="change"
        />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ArrowDown } from '@element-plus/icons-vue'
import request from '@/utils/request.js'
import moment from 'moment'
import { useRouter } from 'vue-router'
const router = useRouter()

const list = ref([])
const total = ref(0)
const pageNum = ref(1)
const pageSize = ref(8)

const init = (currentPage, pageSize) => {
  request
    .post(
      `http://47.106.183.36:8080/adoption/query?pageSize=${pageSize}&pageNum=${currentPage}`,
      {
        statusIn: ['audited']
      }
    )
    .then((res) => {
      list.value = res.data.records
      total.value = res.data.total
      pageNum.value = res.data.current
      pageSize.value = res.data.size
    })
}

init(pageNum.value, pageSize.value)

const change = (currentPage, pageSize) => {
  init(currentPage, pageSize)
}

const pushDetail = (item) => {
  router.push({ path: `/petCare/${item.id}`, query: { userId: item.userId } })
}
</script>

<style scoped>
.img {
  width: 100%;
  height: 600px;
}

.content {
  padding: 0 180px;
}
.list {
  border: 1px solid #d7d7d7;
  margin-top: 15px;
  display: flex;
  flex-wrap: wrap;
  cursor: pointer;
  .item {
    width: 20.2%;
    margin: 10px;
    height: 296px;
    padding: 8px;
    border-radius: 10px;
    border: 1px solid #d7d7d7;
    background-color: #ffffff;
    box-sizing: border-box;
    .name {
      display: flex;
      justify-content: space-between;
    }
    .info {
      display: flex;
      justify-content: space-between;
      color: white;
      .info-1 {
        width: 110px;
        text-align: center;
        background-color: rgb(9, 193, 153);
        border-radius: 10px;
        white-space: nowrap; /* 确保文本不换行 */
        overflow: hidden; /* 隐藏溢出部分的文本 */
        text-overflow: ellipsis; /* 在文本溢出时显示省略号 */
      }
      .info-2 {
        width: 30px;
        text-align: center;
        border-radius: 10px;
        background-color: rgb(2, 167, 240);
      }
      .info-3 {
        color: black;
      }
    }
    .text {
      margin-top: 10px;
      overflow: hidden; /* 超出容器部分隐藏 */
      white-space: nowrap; /* 让文本在一行显示，超出容器部分不换行 */
      text-overflow: ellipsis; /* 超出容器部分显示省略号 */
      font-size: 16px;
    }
  }
}
.pagination {
  display: flex;
  flex-direction: row-reverse;
  margin-top: 20px;
  margin-bottom: 20px;
}
</style>
